var tests = ["test_pinGenerator_shouldGenerate5DigitPin",
             "test_pinGenerator_shouldGenerateAlphaNumPin",
             "test_date_shouldAddDaysToDate",
             "test_util_shouldSanitizeString",
			 "test_date_shouldReturnDateObjectWithTime",
			 "test_date_shouldReturnDateString",
			 "test_date_shouldReturnDBString",
			 "test_date_shouldReturnWeekdayString",
			 "test_date_shouldReturnDaymask",
			 "test_date_shouldReturnDateFromString",
			 "test_date_shouldCheckOverlappingTimespans",
			 "test_money_shouldNotReturnEmptyFormat"];

var test_pinGenerator_shouldGenerate5DigitPin = function() {
    assertEqual(5, tenez.Util.generatePin(5).length);
    assertEqual(5, tenez.Util.generatePin().length);
};

var test_pinGenerator_shouldGenerateAlphaNumPin = function() {
    var alphaNum = /^[A-Za-z0-9]+$/;
    assertMatch(tenez.Util.generatePin(1000), alphaNum);
};

var test_date_shouldAddDaysToDate = function() {
	assertEqual((new Date(2010,0,1,0,0,0)).getTime(), (tenez.Date.addDaysToDate(new Date(2009,0,1,0,0,0), 365)).getTime());
	assertEqual((new Date(2009,0,1,0,0,0)).getTime(), (tenez.Date.addDaysToDate(new Date(2008,0,1,0,0,0), 366)).getTime());
	assertNotEqual((new Date(2009,0,1,0,0,0)).getTime(), (tenez.Date.addDaysToDate(new Date(2008,0,1,0,0,0), 365)).getTime());

	assertEqual((new Date(2010,0,1,0,0,0)).getTime(), (tenez.Date.addDaysToDate(new Date(2011,0,1,0,0,0), -365)).getTime());
}

var test_date_shouldReturnDateObjectWithTime = function() {
	var t2059 = tenez.Date.getTime(20,59);
	assertEqual(20, t2059.getHours());
	assertEqual(59, t2059.getMinutes());	
}

var test_date_shouldReturnDateString = function() {
	assertEqual("2010-01-31 20:03:04", tenez.Date.getDateString(new Date(2010,0,31,20,3,4)));
	assertEqual("31.01.2010", tenez.Date.getDateString(new Date(2010,0,31,20,3,4), "dd.MM.yyyy"));
	assertEqual("31.01.2010 20:03", tenez.Date.getDateString(new Date(2010,0,31,20,3,4), "dd.MM.yyyy HH:mm"));
}

var test_date_shouldReturnDBString = function() {
	assertEqual("2010-01-31 20:03:04+0100", tenez.Date.getDBString(new Date(2010,0,31,20,3,4)));
}

var test_date_shouldReturnWeekdayString = function() {
	assertEqual(gettext("Sonntag"), tenez.Date.getWeekdayString(new Date(2010,0,3,0,0,0)));
	assertEqual(gettext("Freitag"), tenez.Date.getWeekdayString(new Date(2008,1,29,0,0,0)));
}

var test_date_shouldReturnDaymask = function() {
	assertEqual("1______", tenez.Date.getDaymask(new Date(2010,0,4,0,0,0)));
	assertEqual("____1__", tenez.Date.getDaymask(new Date(2008,1,29,0,0,0)));
	assertEqual("______1", tenez.Date.getDaymask(new Date(2010,0,31,0,0,0)));	
}

var test_date_shouldReturnDateFromString = function() {
	assertEqual((new Date(1999,0,12,12,0)).getTime(), (tenez.Date.getDateFromString("12.01.1999 12:00")).getTime());
	assertEqual((new Date(2008,1,29,23,59)).getTime(), (tenez.Date.getDateFromString("29.02.2008 23:59")).getTime());
	assertEqual((new Date(2020,11,31,0,0)).getTime(), (tenez.Date.getDateFromString("31.12.2020 0:00")).getTime());
	assertEqual((new Date(2020,11,31,0,0)).getTime(), (tenez.Date.getDateFromString("31.12.2020 00:00")).getTime());

	assertEqual((new Date(1999,0,12,0,0)).getTime(), (tenez.Date.getDateFromString("12.01.1999")).getTime());
	assertEqual((new Date(2008,1,29,0,0)).getTime(), (tenez.Date.getDateFromString("29.02.2008")).getTime());
	assertEqual((new Date(2020,11,31,0,0)).getTime(), (tenez.Date.getDateFromString("31.12.2020")).getTime());
	
	assertEqual(null, tenez.Date.getDateFromString("12-01-1999"));
	assertEqual(null, tenez.Date.getDateFromString("29.02.2009"));
	assertEqual(null, tenez.Date.getDateFromString("12-31-2020"));
	assertEqual(null, tenez.Date.getDateFromString("2010-12-31"));

	assertEqual((new Date(1970,0,1,0,0)).getTime(), (tenez.Date.getDateFromString("0:00")).getTime());
	assertEqual((new Date(1970,0,1,0,0)).getTime(), (tenez.Date.getDateFromString("00:00")).getTime());
	assertEqual((new Date(1970,0,1,12,01)).getTime(), (tenez.Date.getDateFromString("12:01")).getTime());
	assertEqual((new Date(1970,0,1,23,59)).getTime(), (tenez.Date.getDateFromString("23:59")).getTime());
	
	assertEqual(null, tenez.Date.getDateFromString("0000"));
	assertEqual(null, tenez.Date.getDateFromString("2359"));
	assertEqual(null, tenez.Date.getDateFromString("23-59"));
	assertEqual(null, tenez.Date.getDateFromString("23/59"));
	
	assertEqual(null, tenez.Date.getDateFromString("A"));
	assertEqual(null, tenez.Date.getDateFromString(""));
}

var test_date_shouldCheckOverlappingTimespans = function() {
	assertTrue(tenez.Date.areOverlapping(new Date(1970, 1, 1), new Date(1970, 1, 28), new Date(1970, 1, 1), new Date(1970, 1, 28)));
	assertTrue(tenez.Date.areOverlapping(new Date(1970, 1, 1), new Date(1970, 1, 28), new Date(1970, 0, 1), new Date(1970, 1, 28)));
	assertTrue(tenez.Date.areOverlapping(new Date(1970, 1, 1), new Date(1970, 1, 28), new Date(1970, 1, 2), new Date(1970, 1, 3)));
	assertTrue(tenez.Date.areOverlapping(new Date(1970, 1, 1), new Date(1970, 1, 28), new Date(1970, 1, 27), new Date(1970, 2, 28)));
	assertTrue(tenez.Date.areOverlapping(new Date(1970, 1, 1), new Date(1970, 1, 28), new Date(1970, 0, 1), new Date(1970, 3, 1)));

	assertTrue(tenez.Date.areOverlapping(new Date(1970, 1, 1), new Date(1970, 1, 28), new Date(1970, 1, 1), new Date(1970, 1, 28)));
	assertTrue(tenez.Date.areOverlapping(new Date(1970, 0, 1), new Date(1970, 1, 28), new Date(1970, 1, 1), new Date(1970, 1, 28)));
	assertTrue(tenez.Date.areOverlapping(new Date(1970, 1, 2), new Date(1970, 1, 3), new Date(1970, 1, 1), new Date(1970, 1, 28)));
	assertTrue(tenez.Date.areOverlapping(new Date(1970, 1, 27), new Date(1970, 2, 28), new Date(1970, 1, 1), new Date(1970, 1, 28)));
	assertTrue(tenez.Date.areOverlapping(new Date(1970, 0, 1), new Date(1970, 3, 1), new Date(1970, 1, 1), new Date(1970, 1, 28)));

	assertFalse(tenez.Date.areOverlapping(new Date(1970, 0, 1), new Date(1970, 0, 31), new Date(1970, 1, 1), new Date(1970, 1, 28)));
	assertFalse(tenez.Date.areOverlapping(new Date(1970, 1, 1), new Date(1970, 1, 28), new Date(1970, 0, 1), new Date(1970, 0, 31)));
}

var test_money_shouldNotReturnEmptyFormat = function() {
	assertNotEqual("", tenez.Money.format(100));
}

var test_util_shouldSanitizeString = function() {
    assertEqual("aaaaaaaa-iiiii", tenez.Util.sanitizeCharacters("////äăâàáãåæ,-/(ìíîïî)"));
    assertEqual("aaaaaaaa", tenez.Util.sanitizeCharacters("äăâàáãåæ"));
    assertEqual("ccc", tenez.Util.sanitizeCharacters("ćčç"));
    assertEqual("eeeeeee", tenez.Util.sanitizeCharacters("ęěèéëêë"));
    assertEqual("iiiii", tenez.Util.sanitizeCharacters("ìíîïî"));
    assertEqual("nn", tenez.Util.sanitizeCharacters("ñň"));
    assertEqual("uuuu", tenez.Util.sanitizeCharacters("ùúûü"));
    assertEqual("yy", tenez.Util.sanitizeCharacters("ýÿ"));
    assertEqual("r", tenez.Util.sanitizeCharacters("ř"));
    assertEqual("tt", tenez.Util.sanitizeCharacters("ţț"));              
    assertEqual("sssss", tenez.Util.sanitizeCharacters("şșŝß"));
    assertEqual("sssss-_.", tenez.Util.sanitizeCharacters("     şșŝß    -_!§$%&/((=*'#+:;.<>"));
};
